package com.twotiger.and.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import app.twotiger.p2p.R;

import com.twotiger.and.activity.base.BaseActivity;
import com.twotiger.and.util.ViewUtils;

/**
 * 功能综述：引导用户熟悉软件
 * @author Administrator
 */
public class GuideActivity extends BaseActivity {
    private ViewPager viewPager;
    private List<View> viewList; // Tab页面列表
    private int[] imageIds = new int[] { R.drawable.help_one, R.drawable.help_two, R.drawable.help_three };

    @Override
    protected void processLogic() {
        setGestureEnable(false);
        viewList = new ArrayList<View>();
        for (int i = 0; i < imageIds.length; i++) {
            View view = View.inflate(this, R.layout.item_guide, null);
            view.setBackgroundResource(imageIds[i]);
            viewList.add(view);
            if ((imageIds.length - 1) == i) {
                Button btn = (Button) view.findViewById(R.id.btn);
                btn.setVisibility(View.VISIBLE);
                btn.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (ViewUtils.isFastDoubleClick(v)) {
                            return;
                        }
                        startNewActivity(new Intent(GuideActivity.this, HomeActivity.class), R.anim.push_left_in, R.anim.push_left_out, true);
                    }
                });
            }
        }
        viewPager.setAdapter(pagerAdapter);
    }

    @Override
    protected void setListener() {
        // TODO Auto-generated method stub

    }

    @Override
    protected void findViewById(View view) {
        viewPager = (ViewPager) view.findViewById(R.id.viewpager);

    }

    @Override
    protected View loadViewLayout(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.activity_guide, null);
        return view;
    }

    @Override
    public void onClick(View view) {
        // TODO Auto-generated method stub

    }

    PagerAdapter pagerAdapter = new PagerAdapter() {

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == arg1;
        }

        @Override
        public int getCount() {
            return viewList.size();
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView(viewList.get(position));
        }

        @Override
        public int getItemPosition(Object object) {
            return super.getItemPosition(object);
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(viewList.get(position));
            return viewList.get(position);
        }
    };

    @Override
    protected void onBackPress() {
        // TODO Auto-generated method stub

    }
}
